package simple;

import com.rabbitmq.client.*;
import config.RabbitConfig;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author tuyou_cd
 * @date 2020/12/10 17:03
 */
public class RabbitGet {
    public static void main(String[] args) throws IOException, TimeoutException {

        try (Connection connection = RabbitConfig.getConnection();
             Channel channel = connection.createChannel()) {
            channel.basicQos(64);
            //消费消息是订阅在队列上面
            GetResponse getResp = channel.basicGet("queue_demo", false);
            if (getResp == null) {
                System.out.println("未获取到消息");
            } else {
                System.out.println(getResp == null ? null : new String(getResp.getBody()));
                channel.basicAck(getResp.getEnvelope().getDeliveryTag(), false);
            }
        }
    }
}
